package com.itheima.feiqiu;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class FeiQiu {

    public static void main(String[] args) throws Exception {
        DatagramSocket ds = new DatagramSocket();
        DatagramPacket p = null;//将数据报打包
        for(int i=0;i<=10;i++) {
            String msg = "生前何必久睡,死后定会长眠";
            String str = "1:100:翟超杰:teacher_zhai:32:" + msg;//按照飞鸽传书协议的格式
            InetAddress ip = InetAddress.getByName("255.255.255.255");//请求的ip
            int port = 2425;//飞秋软件端口号
            p = new DatagramPacket(str.getBytes("GBK"), str.getBytes("GBK").length, ip, port);
            ds.send(p);//发送
            System.out.println("发送成功");
        }

       /* DatagramPacket xiaoxi = new DatagramPacket(new byte[1024], new byte[1024].length);//接收 ,最大64k
            while (true) {
                ds.receive(p);
                String re = new String(p.getData(),"GBK");
                System.out.println(re+"*********************");
            }
        }*/
    }
}
